package com.seata.stock.controller;

import com.alibaba.fastjson.JSON;
import com.seata.stock.pojo.Message;
import com.seata.stock.pojo.Stock;
import com.seata.stock.service.StockService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @ClassName: StockController
 * @Author:
 * @Date:
 * @Version: 1.0
 */
@RestController
public class StockController {

    @Autowired
    private StockService stockService;

    @PostMapping("/updateStock")
    @GlobalTransactional
    public Message updateStock(@RequestBody Stock stock){
        if (stockService.updateStock(stock) == 1){
            return new Message(1, "success", null);
        }else if (stockService.updateStock(stock) == 99){
            return new Message(99, "库存不足", null);
        }
        return new Message(0, "未定义", null);
    }
}
